package com.weixing.mall.provider.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.weixing.mall.provider.mapper.AgentDeliveryAddressMapper;
import com.weixing.mall.provider.model.domain.AgentDeliveryAddress;
import com.weixing.mall.provider.model.query.DeliveryQuery;
import com.weixing.mall.provider.model.vo.AgentDeliveryAddressVo;
import com.weixing.mall.provider.service.IAgentDeliveryAddressService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会员模块-收货地址表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2020-05-07
 */
@Service
public class AgentDeliveryAddressServiceImpl extends ServiceImpl<AgentDeliveryAddressMapper, AgentDeliveryAddress> implements IAgentDeliveryAddressService {

    @Override
    public List<AgentDeliveryAddressVo> selectByMobile(String mobile, Long agentId) {
        QueryWrapper<AgentDeliveryAddress> wrapper = new QueryWrapper<>();
        wrapper.eq("contact_phone",mobile).eq("agent_id",agentId);
        List<AgentDeliveryAddress> list = list(wrapper);
        List<AgentDeliveryAddressVo> vos = Lists.newArrayList();
        if (CollUtil.isNotEmpty(list)){
            AgentDeliveryAddressVo vo = null;
            for (AgentDeliveryAddress address:list){
                vo = new AgentDeliveryAddressVo();
                BeanUtils.copyProperties(address,vo);
                vos.add(vo);
            }
        }
        return vos;
    }

    @Override
    public IPage<AgentDeliveryAddressVo> selectOfPage(Page initMpPage, DeliveryQuery query) {

        return baseMapper.selectOfPage(initMpPage,query);
    }

    @Override
    public List<AgentDeliveryAddress> selectByArea(int start ,int end) {
        return baseMapper.selectByArea(start,end);
    }
}
